<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>&lt;GMatchInfo&gt;: </title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
<link rel="home" href="index.html" title="">
<link rel="up" href="ch01.html" title="GLib">
<link rel="prev" href="re39.html" title="&lt;%GLibMarkupParseFlags&gt;">
<link rel="next" href="re41.html" title="&lt;%GLibNormalizeMode&gt;">
<meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
<td><a accesskey="p" href="re39.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="re41.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="id-1.1.41"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>&lt;GMatchInfo&gt;</h2>
<p>&lt;GMatchInfo&gt;</p>
</div>
<div class="refsect1">
<a name="id-1.1.41.2"></a><h2>Description</h2>
<p>A GMatchInfo is an opaque struct used to return information about
matches.</p>
</div>
<div class="refsect1">
<a name="id-1.1.41.3"></a><h2>Functions</h2>
<div class="refsect2">
<a name="id-1.1.41.3.2"></a><h3>expand-references</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:expand-references self string-to-expand))
</pre></div>
<p>Returns a new string containing the text in <em class="parameter"><code>string_to_expand</code></em> with
references and escape sequences expanded. References refer to the last
match done with <em class="parameter"><code>string</code></em> against <em class="parameter"><code>regex</code></em> and have the same syntax used by
<code class="function">g_regex_replace()</code>.
</p>
<p>The <em class="parameter"><code>string_to_expand</code></em> must be UTF-8 encoded even if <span class="type">G_REGEX_RAW</span> was
passed to <code class="function">g_regex_new()</code>.
</p>
<p>The backreferences are extracted from the string passed to the match
function, so you cannot call this function after freeing the string.
</p>
<p><em class="parameter"><code>match_info</code></em> may be <code class="constant">NULL</code> in which case <em class="parameter"><code>string_to_expand</code></em> must not
contain references. For instance "foo\n" does not refer to an actual
pattern and '\n' merely will be replaced with \n character,
while to expand "\0" (whole match) one needs the result of a match.
Use <code class="function">g_regex_check_replacement()</code> to find out whether <em class="parameter"><code>string_to_expand</code></em>
contains references.</p>
<div class="refsect3">
<a name="id-1.1.41.3.2.7"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span> or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string_to_expand</p></td>
<td class="parameter_description">
<p>the string to expand</p>
<p>Passed as <code class="code">string-to-expand</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.3"></a><h3>fetch</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:fetch self match-num))
</pre></div>
<p>Retrieves the text matching the <em class="parameter"><code>match_num</code></em>'th capturing
parentheses. 0 is the full text of the match, 1 is the first paren
set, 2 the second, and so on.
</p>
<p>If <em class="parameter"><code>match_num</code></em> is a valid sub pattern but it didn't match anything
(e.g. sub pattern 1, matching "b" against "(a)?b") then an empty
string is returned.
</p>
<p>If the match was obtained using the DFA algorithm, that is using
<code class="function">g_regex_match_all()</code> or <code class="function">g_regex_match_all_full()</code>, the retrieved
string is not that of a set of parentheses but that of a matched
substring. Substrings are matched in reverse order of length, so
0 is the longest match.
</p>
<p>The string is fetched from the string passed to the match function,
so you cannot call this function after freeing the string.</p>
<div class="refsect3">
<a name="id-1.1.41.3.3.7"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p><span class="type">GMatchInfo</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_num</p></td>
<td class="parameter_description">
<p>number of the sub expression</p>
<p>Passed as <code class="code">match-num</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.4"></a><h3>fetch-all</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:fetch-all self))
</pre></div>
<p>Bundles up pointers to each of the matching substrings from a match
and stores them in an array of gchar pointers. The first element in
the returned array is the match number 0, i.e. the entire matched
text.
</p>
<p>If a sub pattern didn't match anything (e.g. sub pattern 1, matching
"b" against "(a)?b") then an empty string is inserted.
</p>
<p>If the last match was obtained using the DFA algorithm, that is using
<code class="function">g_regex_match_all()</code> or <code class="function">g_regex_match_all_full()</code>, the retrieved
strings are not that matched by sets of parentheses but that of the
matched substring. Substrings are matched in reverse order of length,
so the first one is the longest match.
</p>
<p>The strings are fetched from the string passed to the match function,
so you cannot call this function after freeing the string.</p>
<div class="refsect3">
<a name="id-1.1.41.3.4.7"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.5"></a><h3>fetch-named</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:fetch-named self name))
</pre></div>
<p>Retrieves the text matching the capturing parentheses named <em class="parameter"><code>name</code></em>.
</p>
<p>If <em class="parameter"><code>name</code></em> is a valid sub pattern name but it didn't match anything
(e.g. sub pattern "X", matching "b" against "(?P&lt;X&gt;a)?b")
then an empty string is returned.
</p>
<p>The string is fetched from the string passed to the match function,
so you cannot call this function after freeing the string.</p>
<div class="refsect3">
<a name="id-1.1.41.3.5.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p><span class="type">GMatchInfo</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>name</p></td>
<td class="parameter_description">
<p>name of the subexpression</p>
<p>Passed as <code class="code">name</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.6"></a><h3>fetch-named-pos</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return start-pos end-pos)
  (match-info:fetch-named-pos self name))
</pre></div>
<p>Retrieves the position in bytes of the capturing parentheses named <em class="parameter"><code>name</code></em>.
</p>
<p>If <em class="parameter"><code>name</code></em> is a valid sub pattern name but it didn't match anything
(e.g. sub pattern "X", matching "b" against "(?P&lt;X&gt;a)?b")
then <em class="parameter"><code>start_pos</code></em> and <em class="parameter"><code>end_pos</code></em> are set to -1 and <code class="constant">TRUE</code> is returned.</p>
<div class="refsect3">
<a name="id-1.1.41.3.6.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p><span class="type">GMatchInfo</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>name</p></td>
<td class="parameter_description">
<p>name of the subexpression</p>
<p>Passed as <code class="code">name</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>start_pos</p></td>
<td class="parameter_description">
<p>pointer to location where to store
    the start position, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">start-pos</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>end_pos</p></td>
<td class="parameter_description">
<p>pointer to location where to store
    the end position, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">end-pos</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.7"></a><h3>fetch-pos</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return start-pos end-pos)
  (match-info:fetch-pos self match-num))
</pre></div>
<p>Retrieves the position in bytes of the <em class="parameter"><code>match_num</code></em>'th capturing
parentheses. 0 is the full text of the match, 1 is the first
paren set, 2 the second, and so on.
</p>
<p>If <em class="parameter"><code>match_num</code></em> is a valid sub pattern but it didn't match anything
(e.g. sub pattern 1, matching "b" against "(a)?b") then <em class="parameter"><code>start_pos</code></em>
and <em class="parameter"><code>end_pos</code></em> are set to -1 and <code class="constant">TRUE</code> is returned.
</p>
<p>If the match was obtained using the DFA algorithm, that is using
<code class="function">g_regex_match_all()</code> or <code class="function">g_regex_match_all_full()</code>, the retrieved
position is not that of a set of parentheses but that of a matched
substring. Substrings are matched in reverse order of length, so
0 is the longest match.</p>
<div class="refsect3">
<a name="id-1.1.41.3.7.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p><span class="type">GMatchInfo</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_num</p></td>
<td class="parameter_description">
<p>number of the sub expression</p>
<p>Passed as <code class="code">match-num</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>start_pos</p></td>
<td class="parameter_description">
<p>pointer to location where to store
    the start position, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">start-pos</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>end_pos</p></td>
<td class="parameter_description">
<p>pointer to location where to store
    the end position, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">end-pos</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.8"></a><h3>free</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (match-info:free self))
</pre></div>
<p>If <em class="parameter"><code>match_info</code></em> is not <code class="constant">NULL</code>, calls <code class="function">g_match_info_unref()</code>; otherwise does
nothing.</p>
<div class="refsect3">
<a name="id-1.1.41.3.8.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span>, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.9"></a><h3>get-match-count</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:get-match-count self))
</pre></div>
<p>Retrieves the number of matched substrings (including substring 0,
that is the whole matched text), so 1 is returned if the pattern
has no substrings in it and 0 is returned if the match failed.
</p>
<p>If the last match was obtained using the DFA algorithm, that is
using <code class="function">g_regex_match_all()</code> or <code class="function">g_regex_match_all_full()</code>, the retrieved
count is not that of the number of capturing parentheses but that of
the number of matched substrings.</p>
<div class="refsect3">
<a name="id-1.1.41.3.9.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.10"></a><h3>get-regex</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:get-regex self))
</pre></div>
<p>Returns <span class="type">GRegex</span> object used in <em class="parameter"><code>match_info</code></em>. It belongs to Glib
and must not be freed. Use <code class="function">g_regex_ref()</code> if you need to keep it
after you free <em class="parameter"><code>match_info</code></em> object.</p>
<div class="refsect3">
<a name="id-1.1.41.3.10.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.11"></a><h3>get-string</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:get-string self))
</pre></div>
<p>Returns the string searched with <em class="parameter"><code>match_info</code></em>. This is the
string passed to <code class="function">g_regex_match()</code> or <code class="function">g_regex_replace()</code> so
you may not free it before calling this function.</p>
<div class="refsect3">
<a name="id-1.1.41.3.11.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.12"></a><h3>is-partial-match?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:is-partial-match? self))
</pre></div>
<p>Usually if the string passed to g_regex_match*() matches as far as
it goes, but is too short to match the entire pattern, <code class="constant">FALSE</code> is
returned. There are circumstances where it might be helpful to
distinguish this case from other cases in which there is no match.
</p>
<p>Consider, for example, an application where a human is required to
type in data for a field with specific formatting requirements. An
example might be a date in the form ddmmmyy, defined by the pattern
"^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$".
If the application sees the user’s keystrokes one by one, and can
check that what has been typed so far is potentially valid, it is
able to raise an error as soon as a mistake is made.
</p>
<p>GRegex supports the concept of partial matching by means of the
<span class="type">G_REGEX_MATCH_PARTIAL_SOFT</span> and <span class="type">G_REGEX_MATCH_PARTIAL_HARD</span> flags.
When they are used, the return code for
<code class="function">g_regex_match()</code> or <code class="function">g_regex_match_full()</code> is, as usual, <code class="constant">TRUE</code>
for a complete match, <code class="constant">FALSE</code> otherwise. But, when these functions
return <code class="constant">FALSE</code>, you can check if the match was partial calling
<code class="function">g_match_info_is_partial_match()</code>.
</p>
<p>The difference between <span class="type">G_REGEX_MATCH_PARTIAL_SOFT</span> and
<span class="type">G_REGEX_MATCH_PARTIAL_HARD</span> is that when a partial match is encountered
with <span class="type">G_REGEX_MATCH_PARTIAL_SOFT</span>, matching continues to search for a
possible complete match, while with <span class="type">G_REGEX_MATCH_PARTIAL_HARD</span> matching
stops at the partial match.
When both <span class="type">G_REGEX_MATCH_PARTIAL_SOFT</span> and <span class="type">G_REGEX_MATCH_PARTIAL_HARD</span>
are set, the latter takes precedence.
</p>
<p>There were formerly some restrictions on the pattern for partial matching.
The restrictions no longer apply.
</p>
<p>See pcrepartial(3) for more information on partial matching.</p>
<div class="refsect3">
<a name="id-1.1.41.3.12.9"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.13"></a><h3>matches?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:matches? self))
</pre></div>
<p>Returns whether the previous match operation succeeded.</p>
<div class="refsect3">
<a name="id-1.1.41.3.13.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.14"></a><h3>next?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:next? self))
</pre></div>
<p>Scans for the next match using the same parameters of the previous
call to <code class="function">g_regex_match_full()</code> or <code class="function">g_regex_match()</code> that returned
<em class="parameter"><code>match_info</code></em>.
</p>
<p>The match is done on the string passed to the match function, so you
cannot free it before calling this function.</p>
<div class="refsect3">
<a name="id-1.1.41.3.14.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.15"></a><h3>ref</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (match-info:ref self))
</pre></div>
<p>Increases reference count of <em class="parameter"><code>match_info</code></em> by 1.</p>
<div class="refsect3">
<a name="id-1.1.41.3.15.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.41.3.16"></a><h3>unref</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (match-info:unref self))
</pre></div>
<p>Decreases reference count of <em class="parameter"><code>match_info</code></em> by 1. When reference count drops
to zero, it frees all the memory associated with the match_info structure.</p>
<div class="refsect3">
<a name="id-1.1.41.3.16.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>a <span class="type">GMatchInfo</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
</div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.33.1</div>
</body>
</html>
